#ifndef RSIM_FILEIO_H
#define RSIM_FILEIO_H

/*-------------------------------------------------------------------------- *
* File: FileIO.h                                                             *
* Authors: Kishor Bhalerao                                                   *
* Email : kishor8dm@gmail.com                                                *
* Contributors:                                                              *
* Email:                                                                     *
* copyright (c) 2010 Authors.                                                *
*                                                                            *
* This program is free software: you can redistribute it and/or modify it    *
* under the terms of the GNU General Public License as published by the Free *
* Software Foundation, either version 3 of the License, or any later version.*
*                                                                            *
* This program is distributed in the hope that it will be useful, but        *
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
* or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   *
* for more details. (http://www.gnu.org/licenses/)                           *
* -------------------------------------------------------------------------- */

#include <fstream>

namespace RSIM{

class State;
class SystemData;

namespace FileIO{
        
bool checkFileExists(const char FileName[]="rsimout");

void writeArrayToFile(double const* const *ptr, 
                      const int num_elements, 
                      const int num_array = 1, 
                      const char FileName[]="rsimout",  
                      const int precision=16);

void write_append_ArrayToFile(double const* const *ptr, 
                              const int num_elements, 
                              const int num_array = 1, 
                              const char FileName[]="rsimout",  
                              const int precision=16);
                
void write_append_SingleArrayToFile(const double& val, 
                                    double const *ptr, 
                                    const int num_elements, 
                                    const char FileName[]="rsimout",  
                                    const int precision=16);

void write_append_SingleArrayToFile(std::fstream& OpFile, 
                                    const double& val, 
                                    double const *ptr, 
                                    const int num_elements, 
                                    const char FileName[]="rsimout",  
                                    const int precision=16);

/** 
Write State vector [q u]' 
@param Opfile State Vector along with time stamp is written to this file
@param precision default value is 16
*/
void appendStateVectorToFile(const State& state,  
                             std::fstream& OpFile, 
                             const int precision=16);
                             

/** 
Write State vector [q u]' 
@param Opfile State Vector along with time stamp is written to this file. Note that the order in which the
state will be written is [q u]' per System included in SystemData. e.g If we have 2 systems, the function
writes out [q0 u0 q1 u1]' along with the time stamp
@param precision default value is 16
*/
void appendStateVectorToFile(const SystemData& Data,  
                             std::fstream& OpFile, 
                             const int& precision=16);
        
} // namespace FileIO
} // namespace RSIM
#endif 